import re
from mkdir import mkdir
import urllib


def get_image(html_code, img_name, img_dir):
    reg = r'src="(.+?\.jpg)" size'
    reg_img = re.compile(reg)
    imglist = reg_img.findall(html_code)
    mkdir(img_dir)
    x = 1
    for img in imglist:
        urllib.urlretrieve(img, img_dir + '/' + img_name + '%s.jpg' % x)
        print('##### IMAGE "' + img_name + str(x) + '" IS SAVED IN DIRECTORY "' + img_dir + '/" #####')
        x += 1
